<template>
<div>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="68px">
      <el-form-item label-width="100px" label="学号" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入学号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="用户姓名" prop="userNickname">
        <el-input
          v-model="queryParams.userNickname"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label-width="100px" label="学院" prop="userDept">
        <treeselect
          style="width: 240px"
          clearable
          v-model="queryParams.userDept"
          :options="deptOptions"
          :show-count="true"
          placeholder="请选择学院/班级"
          @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item label-width="100px" label="项目名称" prop="itemName">
        <el-select v-model="queryParams.itemName" placeholder="请选择项目名称" @keyup.enter.native="handleQuery"
                   clearable>
          <el-option
            v-for="dict in dict.type.sport_item"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
  <!----------------------------成绩列表--------------------------->
  <el-row :gutter="20">
    <el-col :span="14" :offset="1">
      <el-card shadow="naiver">
        <div style="" slot="header">
          <span>学生排名</span>
        </div>
        <el-table v-loading="loading" :data="sportApplyUserList">
          <el-table-column label="用户姓名" align="center" prop="userNickname"/>
          <el-table-column label="学院" align="center" prop="params.dept.deptName"/>
          <el-table-column label="比赛项目" align="center" prop="itemName"/>
          <el-table-column sortable label="比赛成绩" align="center" prop="score"/>
          <el-table-column sortable label="排名" align="center" prop="ranking" />
          <el-table-column sortable label="积分" align="center" prop="points" />
        </el-table>
      </el-card>
    </el-col>
    <el-col :span="8">
      <el-card shadow="naiver">
        <div slot="header">
          <span>学院排名</span>
        </div>
        <el-table v-loading="loading" :data="deptRankingList">
          <el-table-column label="学院" align="center" prop="params.dept.deptName" />
          <el-table-column label="积分" align="center" prop="points" />
          <el-table-column label="排名" align="center" prop="ranking" />
        </el-table>
      </el-card>
    </el-col>
  </el-row>

</div>
</template>

<script>
import {getDeptRanking, listSportApplyUser} from "@/api/system/sportApplyUser";
import {treeselect} from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  components: {Treeselect},
  name: "score",
  dicts: ['sport_item', 'item_type'],
  data() {
    return {
      // 部门树选项
      deptOptions: undefined,
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        userNickname: null,
        userPhone: null,
        userDept: null,
        itemId: null,
        itemName: null,
        applyTime: null,
        score: null
      },
      // 显示搜索条件
      showSearch: true,
      // 比赛报名表格数据
      sportApplyUserList: [],
      // 学院排名数据
      deptRankingList: [],
    }
  },
  created() {
    this.getList();
    this.getDeptRankList();
    this.getTreeselect();
  },
  methods: {
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /**
     * 查询学院排名
     */
    getDeptRankList() {
      this.loading = false;
      getDeptRanking().then(response => {
        this.deptRankingList = response.rows;
        this.loading = false;
      })
    },

    /** 查询比赛报名成绩列表 */
    getList() {
      this.loading = true;
      listSportApplyUser(this.queryParams).then(response => {
        this.sportApplyUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>

<style scoped>

</style>
